/**
 * 弯弯工作组
 */
(function($) {
	window.getUrl=function(){
		
		return 'http://www.licaiyibao.com/';
	}
	/*
	*		参数说明
	*		baseUrl:	【字符串】表情路径的基地址['mr','gnl','lxh','bzmh']
	*		pace:		【数字】表情弹出层淡入淡出的速度
	*		dir:		【数组】保存表情包文件夹名字
	*		text:		【二维数组】保存表情包title文字
	*		num:		【数组】保存表情包表情个数
	*		isExist:	【数组】保存表情是否加载过,对于加载过的表情包不重复请求。
	*/
	var rl_exp = {
		baseUrl:	window.getUrl(),
		pace:		200,
		dir:		['mr'],  //表情文件夹目录
		text:[			/*  从网上找了一个例子 提示   表情包title文字，自己补充 */
			[
				'再见','给力','色','傻笑','委屈','顶你','恼火','气愤','爱你','委屈','哈欠','大笑','过来','互粉','凉气','囧','抠鼻','回来了','羞涩','辉辉',
				'蜡烛','迷惑','酷','礼物','鞭炮','灯笼','送祝福','求祝福','兴奋','示爱','奋斗','讨好','不可理喻','贪财','送财运','坏笑','偷着乐','呆了','好的','奥特曼',
				'发言','七嘴八舌','不行','鼓掌','我冤枉','幸福猪','快乐兔','猪头','香一个','不好意思','两行泪','倒下','心凉了','添舌','困了','求饲养','思考','感冒','流汗',
				'没精神'
			],
			[
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试'
			],
			[
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试'
			],
			[
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试',
				'测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试','测试'
			]
		],
		num:		[60,46,82,69],
		isExist:	[0,0,0,0],
		bind:	function(i,textaraeId){
			$("#rl_bq .rl_exp_main").eq(i).find('.rl_exp_item').each(function(){
				$(this).bind('click',function(){
					rl_exp.insertText(document.getElementById(textaraeId),'['+$(this).find('img').attr('title')+']');
					$('#rl_bq').fadeOut(rl_exp.pace);
				});
			});
		},
		/*加载表情包函数*/
		loadImg:function(i,textaraeId){
			var node = $("#rl_bq .rl_exp_main").eq(i);
			for(var j = 0; j<rl_exp.num[i];j++){
				var domStr = 	'<li class="rl_exp_item">' + 
									'<img src="' + rl_exp.baseUrl + 'assets/images/face/' + rl_exp.dir[i] + '/' + j + '.gif" alt="' + rl_exp.text[i][j] + 
									'" title="' + rl_exp.text[i][j] + '" />' +
								'</li>';
				$(domStr).appendTo(node);
			}
			rl_exp.isExist[i] = 1;
			rl_exp.bind(i,textaraeId);
		},
		/*在textarea里光标后面插入文字*/
		insertText:function(obj,str){
			obj.focus();
			if (document.selection) {
				var sel = document.selection.createRange();
				sel.text = str;
			} else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
				var startPos = obj.selectionStart,
					endPos = obj.selectionEnd,
					cursorPos = startPos,
					tmpStr = obj.value;
				obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
				cursorPos += str.length;
				obj.selectionStart = obj.selectionEnd = cursorPos;
			} else {
				obj.value += str;
			}
		},
		init:function(options){
			$("#rl_bq > ul.rl_exp_tab > li > a").each(function(i){
				$(this).bind('click',function(){
					if( $(this).hasClass('selected') )
						return;
					if( rl_exp.isExist[i] == 0 ){
						rl_exp.loadImg(i,options.textaraeId);
					}
					$("#rl_bq > ul.rl_exp_tab > li > a.selected").removeClass('selected');
					$(this).addClass('selected');
					$('#rl_bq .rl_selected').removeClass('rl_selected').hide();
					$('#rl_bq .rl_exp_main').eq(i).addClass('rl_selected').show();
				});
			});
			/*绑定表情弹出按钮响应，初始化弹出默认表情。*/
			$("#"+options.divID).bind('click',function(){
				if( rl_exp.isExist[0] == 0 ){
					rl_exp.loadImg(0,options.textaraeId);
				}
				var w = $(this).position();
				$('#rl_bq').css({"margin-left":"5px","margin-top":"3px"}).fadeIn(400);
			});
			/*绑定关闭按钮*/
			$('#rl_bq a.close').bind('click',function(){
				$('#rl_bq').fadeOut(rl_exp.pace);
			});
			/*绑定document点击事件，对target不在rl_bq弹出框上时执行rl_bq淡出，并阻止target在弹出按钮的响应。*/
			$(document).bind('click',function(e){
				var target = $(e.target);
				if( target.closest("#"+options.divID).length == 1 )
					return;
				if( target.closest("#rl_bq").length == 0 ){
					$('#rl_bq').fadeOut(rl_exp.pace);
				}
			});
		}
	};
	$.fn.wjValidatefn=function(){
		//proper
		
	}
	$.fn.wjEdit=function(options){
		var defaultValues={title:"标题",titleName:"title",contentName:"content",width:"700px",height:"300px"};
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.append("<label>"+obj.title+"：<input name='"+obj.titleName+"' type='text' id='"+obj.titleName+"' /></label>");
			curObj.append("<textarea name='"+obj.contentName+"' id='"+obj.contentName+"' style='width:"+obj.width+";height:"+obj.height+";'></textarea>");
			var editor;
	        KindEditor.ready(function(K) {
                 editor = K.create('#'+obj.contentName,{	
					 allowMediaUpload:false,
					 allowFlashUpload:false,
					 filterMode:true,
					 htmlTags:{ 'br,strong,b,sub,sup,em,i,u,strike,s,del' : []  }
				 });
	        });	
		}	
		);}
	$.fn.wjTree = function(options) {
		var defaultValues = {
			url : "",
			userId : "2",
			uncheckTeamId : "-2"
		};
		var obj = $.extend(defaultValues, options);
		return this.each(function() {
			var curObj = $(this);
			$.post(obj.url + "referral/getFridensList", {
				"userId" : obj.userId,
				"uncheckTeamId" : obj.uncheckTeamId
			}, function(data) {
				var source = data;
				curObj.jqxTree({
					height : '350px',
					source : data,
					checkboxes : true,
					hasThreeStates : true,
					width : '147px',
					theme : 'summer',
					allowDrag : false
				});
				curObj.bind('select', function(event) {
					var htmlElement = event.args.element;
					var item = curObj.jqxTree('getItem', htmlElement);

					if (item.id == 1) {
						curObj.jqxTree('uncheckItem', htmlElement);
					} else {
						curObj.jqxTree('checkItem', htmlElement);
					}
				});
			}, "json");
		});
	}
	$.fn.wjDialog = function(options) {
		var defaultValues = {
			title : "湾湾",
			url : "",
			content : "信息提示"
		}
		var obj = $.extend(defaultValues, options);
		return this.each(function() {
			$(this).load(obj.url + "public_view/dialog", {
				"title" : obj.title,
				"content" : obj.content
			});

		});
	}
	$.fn.wjWindow = function(options) {
		var defaultValus = {
			title : "群祝福",
			url : "",
			accepterId : "",
			userId : ""
		}
		var obj = $.extend(defaultValus, options);
		return this.each(function() {
			$(this).load(obj.url + "public_view/window/" + obj.type + "/" + obj.accepterId + "/"+ obj.userId);
		});
	}
	$.fn.wjmoreClick=function(options){
		var defaultValues={attr:"delId",point:true};
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.undelegate("."+obj.eventClass,"click");  
			curObj.delegate("."+obj.eventClass,"click",function(){
				var para=$.extend({id:$(this).attr(obj.attr)},obj.parameters);
				$.post(obj.url,para,function(data){
					if(obj.point){
						$("#dialogDiv").wjDialog({url:obj.baseUrl+"/",content:data});
						curObj.load(obj.reloadModel);
					}
				});
			});
		});	
	}
	$.fn.wjSubmit=function(options){
		var defaultValues={};
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.undelegate("."+obj.eventClass,"click");
			curObj.delegate("."+obj.eventClass,"click",function(){
				var errorCount=0;
				var para	 ="{";
				var id  	 =$(this).attr(obj.attr);
				$.each(obj.parameters,function(key,val){
					if($("#"+val+"_"+id).val().length==0){
						errorCount++;
						return;
					}
					para +="\""+val+"\":\""+$("#"+val+"_"+id).val()+"\","
					//para[val]=[para[$("#"+val+"_"+id).val()]];
				});
				if(errorCount>0){
					$("#dialogDiv").wjDialog({url:obj.baseUrl+"/",content:"请填写评论内容"});
					return ;
				}
				para=para.substring(0,para.length-1);
				para+="}";
				$.post(obj.url,$.parseJSON(para),function(data){
					$("#"+obj.toggle+id).toggleClass('div_display');
					curObj.load(obj.reload);
				});
			});
			
		});
	}
	$.fn.wjReplay=function(options){
		var defaultValues={attr:"title"};
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.undelegate("."+obj.eventClass,"click");
			curObj.delegate("."+obj.eventClass,"click",function(){
				var id=$(this).attr(obj.attr);
				$("#"+obj.toggle+id).toggleClass('div_display');
			});
			
		});
	}
	$.fn.wjShowMore=function(options){
		
		var defaultValues={pageSize:"pageSize",page:"page",beginNumber:"beginNumber"};
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj   =$(this);
			curObj.undelegate("."+obj.eventClass,"click");
			curObj.delegate("."+obj.eventClass,"click",function(){
				var pageSize	=$(this).attr(obj.pageSize);
				var beginNumber	=$(this).attr(obj.beginNumber);
				var beginNumber =parseInt(beginNumber)+parseInt(pageSize);
				//$(this).attr(obj.beginNumber,beginNumber);
				//alert(obj.controller+"/"+beginNumber+"/"+pageSize+"/1");
				$(this).parent().remove();
				
				console.info(obj.controller+"/"+beginNumber+"/"+pageSize+"/1");
				var appenddDiv =$(this);
				$.post(obj.controller+"/"+beginNumber+"/"+pageSize+"/1",{},function(data){
					console.info(data);
					curObj.append(data);
					curObj.append("<div class='moreFoot_wj'><a style='cursor:pointer' beginNumber='"+beginNumber+"' pageSize='"+pageSize+"' class='showMore'>更多&lt;&lt;&lt; </a></div>");
				},"html");
			});
		});
	};
	$.fn.wjViewDetail=function(options){
		var defaultValues	={attr:"dele"};
		var obj				=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj =$(this);
			curObj.undelegate("."+obj.eventClass,"click");
			curObj.delegate("."+obj.eventClass,"click",function(){
				var id   		= $(this).attr(obj.attr);
				var controller 	= $(this).attr(obj.attr);
				
				$.post(obj.url,{},function(data){
					
					curObj.load(controller);
				});
								 
			});
		});
		
	}
	$.fn.wjPlayVideo = function(options) {
		var player = null;
		var flashvars = {};
		var params = {};
		var attributes = {};
		var swf_url = "";
		var defaultValues = {
			"image" : "",
			"autostart" : false,
			"params" : false,
			"allowfullscreen" : false,
			"wmode" : "transparent",
			"allowscriptaccess" : false,
			"id" : "wanwan",
			"name" : "弯弯",
			"image" : "flv/images_bg.gif",
			"width":530,
			"height":410
		}
		var obj = $.extend(defaultValues, options);
		return this.each(function() {
			var curObj=$(this);
			flashvars.file = obj.video;
			flashvars.autostart = obj.autostart;
			flashvars.image = obj.image;
			params.menu = obj.menu;
			params.allowfullscreen = obj.allowfullscreen;
			params.wmode = obj.wmode;
			params.allowscriptaccess = obj.allowscriptaccess;
			attributes.id = obj.id;
			attributes.name = obj.name;
			swfobject.embedSWF(obj.url+"assets/js/util/flv/player.swf",curObj.attr("id"), obj.width,obj.height,"9.0.0", "expressInstall.swf", flashvars, params,attributes);
		});

	}
	$.fn.wjGetTreeValue = function() {
		var rs = "";
		this.each(function() {
			var curObj = $(this);
			var items = $(this).jqxTree('getCheckedItems');
			if (!items) {
				return;
			}
			var checkedItems = new Array();
			$.each(items, function() {
				checkedItems[checkedItems.length] = this.value;
			});
			for ( var i = 0; i < checkedItems.length; i++) {
				rs += checkedItems[i] == "team" ? "" : checkedItems[i];
				if (i != checkedItems.length - 1 && checkedItems[i] != "team")
					rs += ",";
			}
		});
		return rs;
	}
	
	$.fn.wjDropList=function(options){
		var defaultValues={}
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.append("<input value='"+obj.value+"' type='text' class='drop_down_show' id='drop_down_show'  readOnly='true'/>");
			curObj.append("<input value='"+obj.userId+"' type='hidden' class='drop_down_hide' id='drop_down_hide'  readOnly='true'/>");
			curObj.append("<ul class='drop_down' id='drop_down_ul'></ul>");
			$.each(obj.source,function(i,val){
				$("#drop_down_ul").append("<li id="+val.teamId+"><div class='box_c'><span class='box_s'>+"+val.teamName+"</span></div></li>");
			});
			$("#drop_down_ul").hide();
			curObj.delegate(".drop_down li","click",function(){
				//$("#drop_down_id").val($(this).find(".box_c .box_s").html().substr(1));
				$("#drop_down_show").val($(this).find(".box_c .box_s").html().substr(1));
				$("#drop_down_hide").val($(this).attr("id"));
				$(this).parents(".drop_down").hide();
			});
			curObj.delegate("#"+obj.dropDownId,"click",function(){
				$("#drop_down_ul").show();
			});		
		})
	}
	$.fn.wjTeamList=function(options){
		var defaultValues={}
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.append("<ul class='drop_downt' id='drop_down_team'></ul>");
			$.each(obj.source,function(i,val){
				$("#drop_down_team").append("<a href='"+obj.url+"/"+val.teamId+"'><div class='box_c'><span class='box_s'>+"+val.teamName+"</span></div></a>");
			});
			$("#drop_down_team").hide();
		
			curObj.delegate(curObj,"click",function(){
				$("#drop_down_team").show();
			});		
		})
	}
	$.fn.wjZWTag    = function(options){
		var defaultValues = {};
		var obj = $.extend(defaultValues,options);
		return this.each(function(){
			var curObj = $(this);
			var userName = curObj.find(".zhiwo_bq_c").html();
			var userDesc = curObj.find(".zhiwo_bq_c").attr("desc");
			var oldHtml  = curObj.html();
			curObj.delegate(curObj,"click",function(){
				
				curObj.html("<div class='zhiwo_txt_l'></div><div class='zhiwo_txt_c' contenteditable='true'></div><div class='zhiwo_txt_r'></div>");
				curObj.find(".zhiwo_txt_c").html(userName);
			});
			curObj.delegate(curObj,"mousehour",function(){
				
				curObj.html("<div class='blue_bq'><div><div class='zhiwo_bq_l_hover'><input type='button' class='zw_bq_close' /></div><div class='zhiwo_bq_c_hover'></div><div class='zhiwo_bq_r_hover'></div></div><div class='bq_hover_bg'><p class='bq_hover_bg_desc'></p></div></div>");
				curObj.find(".zhiwo_bq_c_hover").html(userName);
				curObj.find(".bq_hover_bg_desc").html(userDesc);
			});
			curObj.delegate(curObj,"mourseLeave",function(){
				
				curObj.html(oldHtml);
			});
			
		});
	}
	
	$.fn.wjPlayImageRotator =function(options){
		var defaultValues 	= {showCounts:"6"};
		var obj				= $.extend(defaultValues,options);
		var showCounts		= parseInt(obj.showCounts);
		
		return this.each(function(){
			
			var curObj		= $(this);
			
			curObj.append("<div class='images_bg' id='show_image_content'></div>");
			$("#show_image_content").append("<div id='left_arrow_id' class='left_arrow_area'><input type='button'  class='left_arrow' /></div>");
			//<img src='images/images_pic.jpg' width='323' height='462' >
			$("#show_image_content").append("<div style=' float:left; margin-left:120px; margin-top:20px;' id='show_image'></div>");
			$("#show_image_content").append("<div id='right_arrow_id' class='right_arrow_area'><input type='button'  class='right_arrow' /></div>");
			curObj.append("<div class='images_slt' flagId='' id='images_slt_content'></div>");
			curObj.append("<div class='images_slt' flagId=''  id='images_slt_content_hidden'></div>");
			$("#images_slt_content").append("<div class='left_arrow2_area' id='left_arrow2_area_id'><input type='button' class='left_arrow2' /></div>");
			$("#images_slt_content").append("<ul class='pic_slt' id='pic_slt_list_before'></ul>");
			$("#images_slt_content").append("<ul class='pic_slt' id='pic_slt_list'></ul>");
			$("#images_slt_content").append("<ul class='pic_slt' id='pic_slt_list_after'></ul>");
			$("#images_slt_content").append("<div class='right_arrow2_area'  id='right_arrow2_area_id'><input type='button' class='right_arrow2'/></div>");
			var count	=0;
			var imgStr		= "";
			var hidImgStr	= "";
			var source;
			$("#images_slt_content_hidden").hide();
			$.post(obj.previewImageUrl,obj.previewImagePara,function(data){	
				source	= data;
				$.each(data,function(i,val){
					show=(i==0)?"show":"hide";
					if(i==0){
						/*$("#images_slt_content").append("<img src='"+val.imgSrc+"' width='"+323+"' height='"+462+"' />");
						$("#images_slt_content").attr("flagId",val.id);*/
						showImage(obj,val.imgSrc,val.id);
					}
					if(i<showCounts){
						imgStr	 +="<a  class='rototarPreview' pointId='"+i+"' flagId='"+val.id+"' show='"+show+"' des='"+val.imgSrc+"'><li><img src='"+val.imgSrc+"' width='61' height='61' /></li></a>";
					}/*else{
						$("#pic_slt_list_back").append("<a  class='rototarPreview' tip='"+i+"' style='display:none' flagId='"+val.id+"' show='"+show+"' des='"+val.imgSrc+"'><li><img src='"+val.imgSrc+"' width='61' height='61' /></li></a>");
					}*/
					hidImgStr	+="<a  class='rototarPreview' pointId='"+i+"' flagId='"+val.id+"' show='"+show+"' des='"+val.imgSrc+"'><li><img src='"+val.imgSrc+"' width='61' height='61' /></li></a>";
					count++;
				});
				$("#pic_slt_list").html(imgStr);
				$("#images_slt_content_hidden").html(hidImgStr);
			},"json");
			
			
			curObj.undelegate("#left_arrow_id","click");
			curObj.delegate("#left_arrow_id","click",function(){
				console.info("images_slt_content_hidden"+$("#images_slt_content_hidden").html());
				var curImageEle     = $("#images_slt_content_hidden a[show='show']");
				if(parseInt(curImageEle.attr("pointId"))==0)return;
				var showImageEle	= $("#images_slt_content_hidden a[show='show']").prev();
				$("#images_slt_list_hidden a[show='show']").attr("show","hide");
				showImageEle.attr("show","show");
				//showImageEle.attr("des"),showImageEle.attr("flagId")
				showImage(obj,showImageEle.attr("des"),showImageEle.attr("flagId"));
				//getReplayContent(obj);
				
			});
			curObj.undelegate("#right_arrow_id","click");
			curObj.delegate("#right_arrow_id","click",function(){
				var curImageEle		= $("#images_slt_content_hidden a[show='show']");
				if(parseInt(curImageEle.attr("pointId"))>=count-1)return;
				var showImageEle	= $("#images_slt_content_hidden a[show='show']").next();
				$("#images_slt_content_hidden a[show='show']").attr("show","hide");
				showImageEle.attr("show","show");
				showImage(obj,showImageEle.attr("des"),showImageEle.attr("flagId"));
			})
			curObj.undelegate("#left_arrow2_area_id","click");
			curObj.delegate("#left_arrow2_area_id","click",function(){
				var beginNumber		= parseInt($("#pic_slt_list a[show='show']").attr("pointId"))-1;
				if(beginNumber<0)return;
				addPreviewImg(source,obj,beginNumber,showCounts);
			});
			curObj.undelegate("#right_arrow2_area_id","click");
			curObj.delegate("#right_arrow2_area_id","click",function(){
				var beginNumber		= parseInt($("#pic_slt_list a[show='show']").attr("pointId"))+1;
				alert(beginNumber+showCounts+"count ==>"+count);
				if(beginNumber+showCounts>count)return;
				addPreviewImg(source,obj,beginNumber,showCounts);
			});
			curObj.undelegate(".rototarPreview","click");
			curObj.delegate(".rototarPreview","click",function(){
				var showImageEle		=$(this);
				$("#pic_slt_list a[show='show']").attr("show","hide");
				showImageEle.attr("show","show");
				showImage(obj,showImageEle.attr("des"),showImageEle.attr("flagId"));
				getReplayContent(obj,showImageEle.attr("flagId"));
			});
			
		});
		
	};
	function getReplayContent(options,id){
		$.post(options.replayCommentsUrl,options.replayCommentsPara,function(data){
			$("#"+options.replayContent).html(data);
		},"html");
	}
	function addPreviewImg(source,obj,beginNumber,showCounts){
		var imgStr	="";
		if(beginNumber<0){
			return;
		}
		
		$.each(source,function(i,val){
			var show=(i==beginNumber)?"show":"hide";
			//alert("i == >" +i+"show == >"+show +"beginNumber == >"+beginNumber);
			if(i==beginNumber){
				/*$("#images_slt_content").append("<img src='"+val.imgSrc+"' width='"+323+"' height='"+462+"' />");
				$("#images_slt_content").attr("flagId",val.id);*/
				showImage(obj,val.imgSrc,val.id);
			}
			if(i<showCounts+beginNumber&&i>=beginNumber){
				imgStr	+="<a  class='rototarPreview' pointId='"+i+"' flagId='"+val.id+"' show='"+show+"' des='"+val.imgSrc+"'><li><img src='"+val.imgSrc+"' width='61' height='61' /></li></a>";
			}
		});
		$("#pic_slt_list").html(imgStr);
		console.info("imgStr ===>"+imgStr);
		//alert($("#pic_slt_list").html());
		//return imgStr;
	}
	function showImage(options,imageUrl,flagId){
		////showImageEle.attr("des"),showImageEle.attr("flagId")
		$("#show_image").html("<img src='"+imageUrl+"' width='323' height='462' />");
		$("#images_slt_content").attr("flagId",flagId);
		$("#images_slt_content_hidden").attr("flagId",flagId);
		$.post(options.controller,options.parameters,function(data){
			$("#"+options.replayContent).html(data);
		},"html");
		
	}
	$.fn.wjPhotowall=function(options){
		return this.each(function(){
			curObj=$(this);
			$.each(options.source,function(item){
				//alert(options.source[item].imgSrc);
				curObj.append("<li><a href='"+options.source[item].imgSrc+"' title='"+options.source[item].description+"' ><img src='"+options.source[item].imgSrc+"' width='150' height='150'/></a></li>");
			});
		});
	}
	$.fn.wjValidate=function(options){
		var defaultValues={validate:true,parent:'bmlf_lfput',isFlash:false };
		var obj=$.extend(defaultValues,options);
		return this.each(function(){
			var curObj=$(this);
			curObj.val(obj.tip);
			curObj.focus(function(){
				if(obj.tip==curObj.val()||curObj.val()==""){
					curObj.val("");
				}
			}).blur(function(){
				if(obj.tip==curObj.val()||curObj.val()==""){
					curObj.val(obj.tip);
					if(curObj.next(".error").length==0&&obj.validate){
						//".bmlf_lfput"
						curObj.parent("."+obj.parent).append("<span class='error'>"+obj.error+"</span>");
					}
				}else{
					if(curObj.next(".error").length!=0){
						curObj.next(".error").remove();
					}
					if(obj.isFlash){
						curObj.wjGetVedioInfo(obj);
					}
				}
			});	
			obj.button.delegate(curObj,"click",function(){
				curObj.focus();
				obj.button.focus();
			});
		})
		
	}
	$.fn.wjFace=function(options){
		//<表情暂定连个参数 > 一个是  调用该方法的 div id 另一个是 textarea id 
		return this.each(function(){
			var curObj=$(this);
			curObj.parent().append("<div class='rl_exp' id='rl_bq' style='display:none;'></div>");
			$("#rl_bq").append("<ul class='rl_exp_tab clearfix'></ul>");
			$("#rl_bq").append("<ul class='rl_exp_main clearfix rl_selected'></ul>");
			$("#rl_bq").append("<ul class='rl_exp_main clearfix' style='display:none;'></ul>");
			$("#rl_bq").append("<ul class='rl_exp_main clearfix' style='display:none;'></ul>");
			$("#rl_bq").append("<ul class='rl_exp_main clearfix' style='display:none;'></ul>");
			$("#rl_bq").append("<a href='javascript:void(0);' class='close'>×</a>");
			$(".rl_exp ul.rl_exp_tab").append("<li><a href='javascript:void(0);' class='selected'>默认</a></li>");
			/*$(".rl_exp ul.rl_exp_tab").append("<li><a href='javascript:void(0);'>拜年</a></li>");
			$(".rl_exp ul.rl_exp_tab").append("<li><a href='javascript:void(0);'>浪小花</a></li>");
			$(".rl_exp ul.rl_exp_tab").append("<li><a href='javascript:void(0);'>暴走漫画</a></li>");*/
			rl_exp.init(options);			
		});
	};
	$.fn.wjImageShow=function(options){
		return this.each(function(){
			var curObj=$(this);
				curObj.change(function(){
				$('#'+options.form).ajaxSubmit({
					url : options.url,  
					dataType : "json",  
					success : function(data){
						if(parseInt(data.type)==1){
							$("#"+options.appendDiv).before("<li><img src='"+data.path+"' class='imageShow'  width='27px' height='27px'/></li>"); 
							var imgStr="";
							 count=0;
					         $("li .imageShow").each(function(e){imgStr+=$(this).attr("src")+",";count++;});
					         curObj.before("<input type='hidden' value='"+imgStr+"' name='imgSrc'/>");
					         imgStr=imgStr.substr(0,imgStr.length-1);
					         $("#uploadCount").html("已上传"+count+"张图片");
						}else{	
							$("#dialogDiv").wjDialog({url:options.baseUrl,content:data.msg});
						}
					},  
					error:function(){  
						$("#dialogDiv").wjDialog({url:options.baseUrl,content:"系统繁忙请稍后再试"});
					}   
				}); 
			});
			
		});
	}
	$.fn.wjGetVedioInfo=function(options){
		return this.each(function(){
			var curObj=$(this);
				$.post(options.url,{flashUrl:curObj.val()},function(data){
					//$("#"+options.srcImg).val();
					//$("#"+options.title).val();
					if(($("input[name='title']").length==0)){
						curObj.parent().append("<input type='hidden' name='title' value='"+data.title+"'/>");
						curObj.parent().append("<input type='hidden' name='imgSrc' value='"+data.img+"'/>");
						curObj.parent().append("<input type='hidden' name='content' value='"+data.object+"'/>");
					}else{
						if($("input[name='title']").val()!=data.title){
							$("input[name='title']").val(data.title);	
						}
						if($("input[name='imgSrc']").val()!=data.title){
							$("input[name='imgSrc']").val(data.img);
						}
						if($("input[name='content']").val()!=data.title){
							$("input[name='content']").val(data.object);
						}
					}
					$("#"+options.src).attr("src",data.img);
				},"json");			
		});
	};
	$.fn.wjShowHide=function(options){
		 return this.each(function(){
			 curObj=$("#"+options.button);
			 curObj.delegate(curObj,"click",function(){;
				 curObj.next().removeClass("on");
				 curObj.addClass("on");
				 $("#"+options.link).next().hide();
				 $("#"+options.link).show();
			});
		 });
	 }
	 $.fn.imageGallery= function (options) {
	        return this.each(function () {
	            var e = $(this);
	            e.click(function () {
	                var arrPageSizes = imageGallery_getPageSize();
	                var arrPageScroll = imageGallery_getPageScroll();
	                $('Body').append("<div id='imageGallery2-overlay'></div>" +
	                                    "<div id='imageGallery2-wrapper'>" +
	                                        "<div id='imageGallery2-image-container'>" +
	                                              "<div id='imageGallery2-close-bar'><div id='imageGallery2-close-button'><img src='"+options.url+"assets/images/photowall/close-icon.png'/></div></div>" +
	                                              "<div style='clear: left; '>" +
	                                                "<div id='imageGallery2-loadingImage'>" +
	                                                    "<img  src='"+options.url+"assets/images/loading.gif' width='50' height='50'/>" +
	                                                "</div>" +
	                                                "<img id='imageGallery2-image'/>" +
	                                            "</div>" +
	                                         "</div>" +
	                                         "<div id='imageGallery2-image-text-box'>" +
	                                                "<div id='imageGallery2-image-caption'>" +
	                                                "</div>" +
	                                         "</div>" +
	                                    "</div>");
	                $('#imageGallery2-overlay').css({
	                    backgroundColor: 'gray',
	                    opacity: 0.7,
	                    width: arrPageSizes[0],
	                    height: arrPageSizes[1]
	                }).fadeIn();
	                $('#imageGallery2-wrapper').css({
	                    top: arrPageScroll[1] + (arrPageSizes[3] / 10),
	                    left: arrPageScroll[0]
	                }).show();
	                // Load image and set into the image container
	                LoadImageToView(this);
	                // On the click of the image remove the photo box
	                $('#imageGallery2-image').click(function () {
	                    CloseSelectedImage();
	                });
	                return false;
	            });

	        });

	    };

	    function CloseSelectedImage() {
	        $("#imageGallery2-image-text-box").hide();
	        $('#imageGallery2-image-container').animate({ width: 0, height: 0 }, 300, function () { $('#imageGallery2-overlay').remove(); $('#imageGallery2-wrapper').remove(); });
	    }

	    var imageCaption = null;
	    function LoadImageToView(objClick) {
	        // Show the loading
	        $('#imageGallery2-loadingImage').show();
	        // Hide the image before loading the image
	        $('#imageGallery2-image').hide();
	        // preload image before dispalying
	        var objImagePreloader = new Image();
	        var url = objClick.getAttribute('href');
	        imageCaption = objClick.getAttribute('title');
	        objImagePreloader.onload = function () {
	            $('#imageGallery2-image').attr('src', url);
	            // Perfomance an effect in the image container resizing it
	            resizeImageContainer(objImagePreloader.width, objImagePreloader.height);
	            //	clear onLoad, IE behaves irratically with animated gifs otherwise
	            objImagePreloader.onload = function () { };
	        };
	        objImagePreloader.src = url;
	    };
	    function resizeImageContainer(intImageWidth, intImageHeight) {
	        var containerBorderSize = 0;
	        var containerResizeSpeed = 500;
	        // Get current width and height
	        var intCurrentWidth = $('#imageGallery2-image').width();
	        var intCurrentHeight = $('#imageGallery2-image').height();
	        // Get the width and height of the selected image plus the padding
	        var intWidth = (intImageWidth + (containerBorderSize * 2)); // Plus the image′s width and the left and right padding value
	        var intHeight = (intImageHeight + (containerBorderSize * 2)); // Plus the image′s height and the left and right padding value
	        // Diferences
	        var intDiffW = intCurrentWidth - intWidth;
	        var intDiffH = intCurrentHeight - intHeight;
	        // set width and height using animation effects
	        $('#imageGallery2-image-container').animate({ width: intWidth, height: intHeight }, containerResizeSpeed, function () { ShowImageAfterLoading(); });
	        $('#imageGallery2-image-text-box').css({ width: intImageWidth });
	    };
	    function ShowImageAfterLoading() {
	        $('#imageGallery2-loadingImage').hide();
	        $('#imageGallery2-image').fadeIn(function () { ShowImageData(); });
	        $('#imageGallery2-close-button').show();
	        $('#imageGallery2-close-button').click(function () { CloseSelectedImage(); });
	    };
	    function ShowImageData() {
	        if (imageCaption != null) {
	            $('#imageGallery2-image-text-box').slideDown('fast');
	            //$('#imageGallery2-image-caption').hide();
	            $('#imageGallery2-image-caption').html(imageCaption);
	        }
	    }
	    function imageGallery_getPageSize() {
	        var xScroll, yScroll;
	        /*******************************************************
	        *******浏览器的高度 和宽度 GET SCROLL BAR ***************
	        ********************************************************/
	        if (window.innerHeight && window.scrollMaxY) { 
	            xScroll = window.innerWidth + window.scrollMaxX;
	            yScroll = window.innerHeight + window.scrollMaxY;
	        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
	            xScroll = document.body.scrollWidth;
	            yScroll = document.body.scrollHeight;
	        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	            xScroll = document.body.offsetWidth;
	            yScroll = document.body.offsetHeight;
	        }
	        var windowWidth, windowHeight;
	        /*******************************************************
	        ********* 选择内容的 高度 和宽度 GET Window Width *******
	        ********************************************************/
	        if (self.innerHeight) {	// all except Explorer   所有的浏览器都支持 除了 IE 
	            if (document.documentElement.clientWidth) {
	                windowWidth = document.documentElement.clientWidth;
	            } else {
	                windowWidth = self.innerWidth;
	            }
	            windowHeight = self.innerHeight;
	        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode   IE 6
	            windowWidth = document.documentElement.clientWidth;
	            windowHeight = document.documentElement.clientHeight;
	        } else if (document.body) { // other Explorers
	            windowWidth = document.body.clientWidth;
	            windowHeight = document.body.clientHeight;
	        }
	        // for small pages with total height less then height of the viewport
	        if (yScroll < windowHeight) {
	            pageHeight = windowHeight;
	        } else {
	            pageHeight = yScroll;
	        }
	        // for small pages with total width less then width of the viewport 
	        if (xScroll < windowWidth) {
	            pageWidth = xScroll;
	        } else {
	            pageWidth = windowWidth;
	        }
	        arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	        return arrayPageSize;
	    };
	    function imageGallery_getPageScroll() {
			/*******************************************************
	        **** 获得滚动条的顶部到网页顶部的距离 GET Window Width**
	        ********************************************************/
		    //window.pageYOffset：Netscape属性，指的是滚动条顶部到网页顶部的距离
	        var xScroll, yScroll;
	        if (self.pageYOffset) {
	            yScroll = self.pageYOffset;
	            xScroll = self.pageXOffset;
	        } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
	            yScroll = document.documentElement.scrollTop;
	            xScroll = document.documentElement.scrollLeft;
	        } else if (document.body) {// all other Explorers
	            yScroll = document.body.scrollTop;
	            xScroll = document.body.scrollLeft;
	        }
	        arrayPageScroll = new Array(xScroll, yScroll);
	        return arrayPageScroll;
	    };

})(jQuery)
